﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.Expenses;

namespace University.Workshop.Presentation.Expenses
{
    /// <summary>
    /// Interaction logic for SearchExpense.xaml
    /// </summary>
    public partial class SearchExpense : Page, ISearchExpenseView
    {
        PresenterSearchExpense pSearchWaterPurchase;

        public SearchExpense()
        {
            InitializeComponent();
            pSearchWaterPurchase = new PresenterSearchExpense(this);
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "Buscar Egreso";
        }

        private void SearchBtn_Click(object sender, RoutedEventArgs e)
        {
            pSearchWaterPurchase.SearchWaterPurchase();
        }

        #region ISearchWaterPurchaseView Members

        public ICollection<Model.Expense> ExpenseFinded
        {
            get
            {
                if (ExpenseFindedDgv.ItemsSource == null)
                    new List<Model.Expense>();
                return (ICollection<Model.Expense>)ExpenseFindedDgv.ItemsSource;
            }
            set
            {
                ExpenseFindedDgv.ItemsSource = null;
                ExpenseFindedDgv.ItemsSource = value;
            }
        }

        public void NotifyErrorMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Error!!!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }

        public void NotifySystemMessage(string p)
        {
            //MessageBox.Show(App.Current.MainWindow, MessageValue, "Atencion!!!", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }

        private void ShowUserBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Expenses.Read((Model.Expense)ExpenseFindedDgv.SelectedItem));
        }

        private void ModifyUserBtn_Click(object sender, RoutedEventArgs e)
        {
            this.NavigationService.Navigate(new Expenses.Modify((Model.Expense)ExpenseFindedDgv.SelectedItem));
        }

        public string Receipt
        {
            get
            {
                return ReceiptTxBx.Text;
            }
            set
            {
                ReceiptTxBx.Text = value;
            }
        }

        public DateTime SpendDate
        {
            get
            {
                return DateTime.Parse(SpendDateDpck.Text);
            }
            set
            {
                SpendDateDpck.Text = value.ToString();
            }
        }

        public short Item
        {
            get
            {
                return (short)ItemDdl.SelectedIndex;
            }
            set
            {
                //CourtesyChk.IsChecked = value;
            }
        }

        public bool NotifyConfirmationMessage(string MessageValue)
        {
            return MessageBox.Show(App.Current.MainWindow,
                MessageValue,
                "Atención!!!",
                MessageBoxButton.YesNo,
                MessageBoxImage.Information,
                MessageBoxResult.Yes,
                MessageBoxOptions.RightAlign) == MessageBoxResult.Yes;
        }

        public Model.Expense ExpenseSelected
        {
            get { return (Model.Expense)ExpenseFindedDgv.SelectedItem; }
        }

        #endregion

        private void CantCupyPasteOrCut(object sender, CanExecuteRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Copy)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Cut)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Paste)
                e.Handled = true;
        }

        private void NumsEspacioTxt_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                e.Handled = true;
            }
        }

        private void SoloNums_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            foreach (char ch in e.Text)
            {
                e.Handled = !(char.IsDigit(ch));
            }
        }

        private void SpendDateDpck_PreviewTextInput_1(object sender, TextCompositionEventArgs e)
        {
            e.Handled = true;
        }
    }
}
